package de.probstl.core;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.appfuse.model.BaseObject;
import org.appfuse.model.User;

/**
 * Ein Einkauf bei einer Tankstelle
 */
@Entity(name = "purchase")
public class Purchase extends BaseObject
{
	/** Die eindeutige Id des Einkaufs */
	private Long m_Id;

	/** Die Anzahl der Lister */
	private float m_Liters;

	/** Der Betrag in Euro der bezahlt wurde */
	private float m_Amount;

	/** Der Kilometerstand */
	private long m_Mileage;

	/** Zeitpunkt an dem getankt wurde */
	private Date m_Purchased;

	/** Der Benutzer der hier getankt hat */
	private User m_Owner;

	/** Die Tankstelle an der getankt wurde */
	private Station m_Station;

	/** Das Fahrzeug das betankt wird */
	private Vehicle m_Vehicle;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId()
	{
		return m_Id;
	}

	@Column(name = "liters", nullable = false)
	public float getLiters()
	{
		return m_Liters;
	}

	@Column(name = "amount", nullable = false)
	public float getAmount()
	{
		return m_Amount;
	}

	@Column(name = "mileage")
	public float getMileage()
	{
		return m_Mileage;
	}

	@Column(name = "purchased")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getPurchased()
	{
		return m_Purchased;
	}

	@ManyToOne
	public User getOwner()
	{
		return m_Owner;
	}

	@ManyToOne
	public Station getStation()
	{
		return m_Station;
	}

	@ManyToOne
	public Vehicle getVehicle()
	{
		return m_Vehicle;
	}

	/**
	 * @param m_Id
	 *            the m_Id to set
	 */
	public void setId(Long id)
	{
		m_Id = id;
	}

	public void setLiters(float liters)
	{
		m_Liters = liters;
	}

	public void setAmount(float amount)
	{
		m_Amount = amount;
	}

	public void setStation(Station station)
	{
		m_Station = station;
	}

	public void setMileage(long mileage)
	{
		m_Mileage = mileage;
	}

	public void setPurchased(Date purchased)
	{
		m_Purchased = purchased;
	}

	public void setVehicle(Vehicle vehicle)
	{
		m_Vehicle = vehicle;
	}

	public void setOwner(User owner)
	{
		m_Owner = owner;
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((m_Id == null) ? 0 : m_Id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Purchase other = (Purchase) obj;
		if (m_Id == null)
		{
			if (other.m_Id != null)
				return false;
		} else if (!m_Id.equals(other.m_Id))
			return false;
		return true;
	}

	@Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("FuelPurchase [m_Id=");
		builder.append(m_Id);
		builder.append(", m_Liters=");
		builder.append(m_Liters);
		builder.append(", m_Amount=");
		builder.append(m_Amount);
		builder.append("]");
		return builder.toString();
	}
}
